<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>
</head>

<body>
    <div>
        <button type="button" id="btnUpdate">更改style节点</button>
    </div>
    <div class="div">文本</div>

            <style id="ss-test">

                .div {
                    background-color: red;
                    font-size: 30px;
                }

                div {
                    font-size: 26px
                }
            </style>


    <script>

        document.getElementById("btnUpdate").addEventListener("click", updateStyleNode)

        function updateStyleNode() {
            const styleSheets = Array.from(document.styleSheets);
            // ownerNode获得styleSheet对应的节点
            const st = styleSheets.find(s=> s.ownerNode.id === "ss-test");
            // 选过选择器找到对应的rule
            const rule = Array.from(st.rules).find(r=> r.selectorText === ".div");

            // 兼容性 
            const styleMap = rule.styleMap;
            styleMap.set("background-color", "blue");

        }

    </script>

</body>

</html>